#include <iostream>
#include <unordered_set>
using namespace std;
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};
// 使用哈希表秒杀！！
std::unordered_set<ListNode*> nset;
class Solution {
public:
    ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
		while (pHead1 != nullptr) nset.insert(pHead1), pHead1 = pHead1->next;
		while (pHead2 != nullptr) {
			if (nset.count(pHead2)) return pHead2;
			pHead2 = pHead2->next;
		}

		return nullptr;
    }
};
